package com.woniuxy.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.entity.Address;
import com.woniuxy.mapper.AddressMapper;
import com.woniuxy.service.AddressService;

@Service
public class AddressServiceImpl implements AddressService {

	@Autowired
	private AddressMapper addressMapper;

	@Override
	public List<Address> findAddressByUid(int u_id) {

		return addressMapper.findAddressByUid(u_id);
	}

	@Override
	public Address findAddressByUidY(int u_id) {

		return addressMapper.findAddressByUidY(u_id);
	}

	@Override
	public Boolean updataAddressY(int u_id, int a_id) {
		int n = addressMapper.updataAddressN(u_id);
		int y = addressMapper.updataAddressY(a_id);

		return n > 0 && y > 0;
	}

	@Override
	public Boolean addAddress(Address address) {
		if (addressMapper.findAddressByUid(address.getU_id()) == null) {
			address.setType("y");
		} else {
			address.setType("n");
		}

		return addressMapper.addAddress(address) > 0;
	}

	@Override
	public Boolean delAddress(int a_id) {

		return addressMapper.delAddress(a_id) > 0;
	}
}
